#include <QCoreApplication>
#include <QImage>
#include <iostream>

// The program searches for a "sequential" and "parallel" directory,
// containing the following files:
// 1.jpg : horizontal edges
// 2.jpg : vertical edges
// 3.jpg : 45 degree edges
// 4.jpg : all edges
// 5.jpg : blur (use default option, the middle one)
// 6.jpg : motion blur (use the first option: \)
// 7.jpg : sharpen
// 8.jpg : excessive edges
// 9.jpg : emboss
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    int countEqual = 0;
    for (int imageNumber = 1; imageNumber <= 9; ++imageNumber)
    {
        QString s1 = "sequential//" + QString::number(imageNumber) + ".jpg";
        QImage im1(s1);

        if (im1.isNull())
        {
            std::cout << "Cannot open file: " << s1.toStdString() << std::endl;
            break;
        }

        QString s2 = "parallel//" + QString::number(imageNumber) + ".jpg";
        QImage im2(s2);

        if (im2.isNull())
        {
            std::cout << "Cannot open file: " << s2.toStdString() << std::endl;
            break;
        }

        bool l = true;
        int i = 0;
        int j = 0;
        int indi;
        int indj;

        while (l && (i < im2.width()))
        {
            while (l && (j < im2.height()))
            {
                l = (im1.pixel(i, j) == im2.pixel(i, j));
                indj = j;
                j++;
            }
            indi = i;
            i++;
        }

        if (l)
        {
            countEqual++;
            std::cout << imageNumber << ": sequential and parallel transformation's results are equal"
                         << std::endl;
        }
        else
        {
            std::cout << imageNumber << ": sequential and parallel transformation's results differ at"
                         << "(" << indi << ";" << indj << ")" << std::endl;

        }
    }

    std::cout << "9 / " << countEqual << " tests passed" << std::endl;

    return a.exec();
}
